<script setup>
import { h, onMounted, ref, resolveDirective, withDirectives } from 'vue'

import {
  useMessage,
  NButton,
  NForm,
  NFormItem,
  NInput,
  NInputNumber,
  NPopconfirm,
  NTreeSelect,
  NTag,
  NSwitch,
  NFlex,
  NAvatar,
  NSelect,
  NImage,
  NDataTable,
} from 'naive-ui'

import CommonPage from '@/components/page/CommonPage.vue'
import QueryBarItem from '@/components/query-bar/QueryBarItem.vue'
import CrudModal from '@/components/table/CrudModal.vue'
import CrudTable from '@/components/table/CrudTable.vue'
import TheIcon from '@/components/icon/TheIcon.vue'
import { getToken } from '@/utils'
import { renderIcon } from '@/utils'
import { useCRUD } from '@/composables'
// import { loginTypeMap, loginTypeOptions } from '@/constant/data'
import api from '@/api'
import { router } from '@/router'
import default_image from '@/assets/images/mz.jpg'

defineOptions({ name: '支付流水' })

const $table = ref(null)
const queryItems = ref({})
const vPermission = resolveDirective('permission')
const base_path = import.meta.env.VITE_BASE

const {
  modalVisible,
  modalTitle,
  modalLoading,
  handleSave,
  modalForm,
  modalFormRef,
  handleEdit,
  handleDelete,
  handleAdd,
} = useCRUD({
  name: '支付流水',
  initForm: {},
  refresh: () => $table.value?.handlerefresh(),
})
const isDisabled = ref(false)

onMounted(() => {
  $table.value?.handleSearch()
})

const columns = [
  {
    title: 'ID',
    key: 'id',
    width: 100,
    align: 'center',
    ellipsis: { tooltip: true },
  },

  {
    title: '订单id',
    key: 'order_id',
    width: 100,
    align: 'center',
    ellipsis: { tooltip: true },
    fixed: 'left',
  },
    {
    title: '流水号',
    key: 'out_trade_no',
    width: 200,
    align: 'center',
    ellipsis: { tooltip: true },
  },{
    title: '商户流水号',
    key: 'transaction_id',
    width: 200,
    align: 'center',
    ellipsis: { tooltip: true },
  },
{
    title: '金额',
    key: 'amount',
    width: 100,
    align: 'center',
    ellipsis: { tooltip: true },

  },

  {
    title: '支付成功时间',
    key: 'success_time',
    width: '100',
    align: 'center',
    ellipsis: { tooltip: true },
  },

]

function formatTimestamp(timestamp) {
  const date = new Date(timestamp)
  const pad = (num) => num.toString().padStart(2, '0')
  const year = date.getFullYear()
  const month = pad(date.getMonth() + 1) // 月份从0开始，所以需要+1
  const day = pad(date.getDate())
  const hours = pad(date.getHours())
  const minutes = pad(date.getMinutes())
  const seconds = pad(date.getSeconds())
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
}
const datetimeRange = ref()
const handleDateRangeChange = (value) => {
  queryItems.value.start_time = formatTimestamp(value[0])
  queryItems.value.end_time = formatTimestamp(value[1])
}
async function  on_excel(){
   await api.onAppointmentExcel({start_time:queryItems.value.start_time,end_time:queryItems.value.end_time})
   data.show_excel = true
   //$message?.success('正在生成下载文件,请前往下载中心查看')
}
function go_excel(){
  router.push({ path: '/downloads/list' });
}
</script>

<template>
  <!-- 业务页面 -->
  <CommonPage show-footer title="支付流水">
    <template #action>
      <div>

      </div>
    </template>
    <!-- 表格 -->
    <CrudTable
        ref="$table"
        v-model:query-items="queryItems"
        :columns="columns"
        :get-data="api.getOrdersWater"

    >
      <template #queryBar>
        <QueryBarItem label="订单编号" :label-width="80">
          <NInput
              v-model:value="queryItems.order_id"
              clearable
              type="text"
              placeholder="请输入订单编号"
              @keypress.enter="$table?.handleSearch()"
          />
        </QueryBarItem>
      </template>
    </CrudTable>
  </CommonPage>
</template>
